//
//  ZRBaseViewController.swift
//  Sina
//
//  Created by 张锐 on 16/2/25.
//  Copyright © 2016年 zhangr. All rights reserved.
//

import UIKit

class ZRBaseViewController: UITableViewController ,ZRVisitorViewDelegate{

    var visitor :ZRVisitorView?
    
    override func loadView() {
        
//        if ZRTokenModel.readFromSand("token&user.db")?.access_token != nil {
        if ZRTokenModelView.shareInstance.isLogin!{
//        =============================================teacher也不好使
            super.loadView()
        
        }else{
        
            showVisitorView()
        
        }
    }
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
   
    }
    /**
     加载访客视图
     */
    func showVisitorView(){
    
        visitor = ZRVisitorView()
        
        visitor?.delegate = self
        
        view = visitor
        
        setupNav()
    
    }
    /**
     设置nav
     */
    func setupNav(){
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "register")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "login")
    
    
    }
}


/**
*  访客视图代理
*/
extension ZRBaseViewController{

    func login() {
        
        print("登录")
    }
    
    func register() {
        
        presentViewController(UINavigationController(rootViewController: ZRLoginViewController()), animated: true) { () -> Void in
            
        }
        
    }


}
